package com.seleniti.enpareja.web.desktop.client.ui.widget;

import org.ioc.commons.ui.HasValue;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.Visibility;
import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.CssResource;
import com.google.gwt.resources.client.CssResource.ImportedWithPrefix;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Label;

public class PendingMark extends Composite implements HasValue<Integer>, com.google.gwt.user.client.TakesValue<Integer> {

	public static interface Resource extends ClientBundle {
		@Source("PendingMark.css")
		Style style();
	}

	@ImportedWithPrefix("pendingMark")
	public static interface Style extends CssResource {
		String mark();
	}

	private Integer value;
	private Label label;

	public PendingMark() {
		Style style = GWT.<Resource> create(Resource.class).style();
		style.ensureInjected();
		this.label = new Label();
		initWidget(label);
		this.label.setStyleName(style.mark());
		this.label.getElement().getStyle().setVisibility(value != null && value > 0 ? Visibility.VISIBLE : Visibility.HIDDEN);
	}

	@Override
	public void setValue(Integer value) {
		this.getWidget().getElement().getStyle().setVisibility(value != null && value > 0 ? Visibility.VISIBLE : Visibility.HIDDEN);
		this.value = value;
		this.label.setText(value != null ? value.toString() : "");
	}

	@Override
	public Integer getValue() {
		return this.value;
	}

}
